package com.ruoyi.statisticalCenter.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.qualityControl.domain.ScOutBoundSendSheet;
import com.ruoyi.qualityControl.service.ScOutBoundSendSheetService;
import com.ruoyi.statisticalCenter.domain.ScContractAreaSendCostCalculate;
import com.ruoyi.statisticalCenter.domain.vo.ScContractAreaSendCostCalculateVo;
import com.ruoyi.statisticalCenter.service.ScContractAreaSendCostCalculateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sc/contractAreaSendCostCalculate")
@Api(tags = "统计中心-出港发件成本报表")
public class ScContractAreaSendCostCalculateController {
    @Autowired
    private ScContractAreaSendCostCalculateService scContractAreaSendCostCalculateService;
    @Autowired
    private ScOutBoundSendSheetService scOutBoundSendSheetService;

    @ApiOperation("汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody ScContractAreaSendCostCalculateVo vo) {
        if (vo != null) {
            String startTime = vo.getStartTime().replace("-", "");
            String endTime = vo.getEndTime().replace("-", "");
            vo.setStartTime(startTime);
            vo.setEndTime(endTime);
        }
        return scContractAreaSendCostCalculateService.collect(vo);
    }

    @ApiOperation("显示承包区配置列表")
    @GetMapping("selectAll")
    public R selectAll(@RequestBody PageDate pageDate) {
        return R.ok(PageInfo.info(scOutBoundSendSheetService.selectAll(pageDate)));
    }

    @ApiOperation("查询承包区配置")
    @GetMapping("/selectSendDisposition/{contractAreaId}")
    public R selectSendDisposition(@PathVariable String contractAreaId) {
        return R.ok(scOutBoundSendSheetService.selectSendDisposition(contractAreaId));
    }

    @ApiOperation("修改承包区配置")
    @PostMapping("/update")
    public R update(@RequestBody ScOutBoundSendSheet scOutBoundSendSheet) {
        Boolean isUpdate = scOutBoundSendSheetService.update(scOutBoundSendSheet);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }

    }


}
